package com.star.controller.admin;

import com.star.dto.BusinessDTO;
import com.star.dto.BusinessPageQueryDTO;
import com.star.entity.Business;
import com.star.result.PageResult;
import com.star.result.Result;
import com.star.service.BusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminBusinessController")
@RequestMapping("/admin/business")
@Slf4j
// Swagger接口文档
@Api(tags = "管理员端商家管理接口")
public class BusinessController {
    @Autowired
    private BusinessService businessService;
    /**
     * 新增商家
     * @param businessDTO body参数
     * @return
     */
    @PostMapping
    @ApiOperation("新增商家")
    public Result<String> addEmployee(@RequestBody BusinessDTO businessDTO) {
        log.info("新增商家{}", businessDTO);
        businessService.add(businessDTO);
        return Result.success();
    }

    /**
     * 商家分页查询
     * @param businessPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("商家分页查询")
    public Result<PageResult> page(BusinessPageQueryDTO businessPageQueryDTO){
        log.info("商家分页查询{}", businessPageQueryDTO);
        PageResult pageResult = businessService.pageQuery(businessPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 启用/禁用商家状态
     * @param status 路径参数
     * @param id query参数
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用/禁用商家状态")
    public Result<String> updateStatus(@PathVariable Integer status, Long id){
        log.info("启用禁用商家状态{}{}", status, id);
        businessService.updateStatus(status, id);
        return Result.success();
    }
    /**
     * 根据id查询商家信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询商家信息")
    public Result<Business> getById(@PathVariable Long id){
        log.info("商家id{}", id);
        Business business = businessService.getById(id);
        return Result.success(business);
    }

    /**
     * 更新管商家信息
     * @param businessDTO body参数
     * @return
     */
    @PutMapping
    @ApiOperation("更新商家信息")
    public Result<String> update(@RequestBody BusinessDTO businessDTO){
        log.info("更新商家信息{}", businessDTO);
        businessService.update(businessDTO);
        return Result.success();
    }
}
